
function identity<T>(arg: T): T{
    return arg;
}

let output1 = identity<string>("this is string1");
document.write(`<p>${typeof(output1)}</p>`);
let output2 = identity("this is string2");  // 编译器自动类型推导为string
document.write(`<p>${typeof(output2)}</p>`);

// 泛型类型变量
let myIden: <T>(arg: T)=>T = identity;

// 泛型接口
interface GenericIden{
    <T>(arg: T):T;
    //name: string;// 
}
let myIdenInte:GenericIden = identity;

// 泛型作为接口参数
interface GenericIdenFn<T>{
    (arg: T):T;
}
let myIdenInteGen:GenericIdenFn<number> = identity;

// 泛型类
class GenericNumber<T>{
    zeroValue: T;
    add: (x: T, y: T)=>T;
}











